package com.example.testjni;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.Looper;
import android.util.Log;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    // Used to load the 'native-lib' library on application startup.
    static {
        System.loadLibrary("native-lib");
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Example of a call to a native method
        TextView tv = findViewById(R.id.sample_text);
        tv.setText(stringFromJNI());
        //testFirst(2, "androidtest");
        //int j_i[] = {1, 2, 3};
        //testArray(j_i, new String[] {"hello", "bbbb"});
        //Log.e("JAVA", j_i[0] + "");

        //testObject(new TestBean("陈益洪", "123456"), "引用类型");

        //dynamicJavaTest();
        //dynamicJavaTest2(10);

        testThread();
    }

    public void updateUI() {
        if(Looper.myLooper() == Looper.getMainLooper()) {
            Log.e("JAVA", "主线程更新UI");
        } else {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Log.e("JAVA", "子线程切换到主线程更新UI");
                }
            });
        }
    }

    /**
     * A native method that is implemented by the 'native-lib' native library,
     * which is packaged with this application.
     */
    public native String stringFromJNI();

    public native void testFirst(int i, String j);

    private native void testArray(int[]i, String[] j);

    private native void testObject(TestBean testBean, String str);


    //这个函数用动态方法调用
    private native void dynamicJavaTest();
    private native int dynamicJavaTest2(int i);

    //线程
    private native void testThread();
}
